//
//  YahooUser.m
//  HelloWorld
//
//  Created by Martin Le C. on 5/11/09.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "YahooUser.h"

@implementation YahooUser
@synthesize yahooId;
@synthesize status;
@synthesize name;
@synthesize onPager;
@synthesize onChat;
@synthesize ignored;
@synthesize customStatusMessage;
@synthesize customStatusBusy;
@synthesize groupCount;
- (id) init:(NSString*)i st:(NSInteger)st ch:(BOOL)ch pg:(BOOL)pg {
	self.groupCount = 0;
	[self update:i st:st ch:ch pg:pg];
	return self;
}
- (id) init:(NSString*)i st:(NSString*)st ch:(NSString*)ch pig:(NSString*)pig {
	self.groupCount = 0;
	[self update:i st:st ch:ch pig:pig];
	return self;
}
-(void) adjustGroupCount:(NSInteger)inc{ 
	self.groupCount+=inc; 
}
- (id) init:(NSString*)i {
	self.groupCount = 0;
	[self init:i st:STATUS_OFFLINE ch:NO pg:NO];
	return self;
}
- (NSString *) toURIString {
	return [NSString stringWithFormat:@"id=%@ status=0x%x chat?=%@ paper?=%@ ignore?=%@ custMesg=%@ custBusy?=%@ friend?=%@", self.yahooId, self.onChat, self.onPager, self.ignored, self.customStatusMessage, self.customStatusBusy, [self isFriend]];
}
// -----------------------------------------------------------------
// Update this object's details
// -----------------------------------------------------------------
// -----This is the new version, where 13=combined pager/chat
- (void) update:(NSString *)i st:(NSString *)st vs:(NSString *)vs {
	NSInteger Visibility	=	0;
	Visibility = (vs==nil) ? 0 : [vs integerValue];
	[self update:i st:[st integerValue] ch:((Visibility&2)>0) pg:((Visibility&1)>0)];
}
// -----This is the old version, when 13=pager and 17=chat
/*void update(String i,String st,String ch,String pg)
	{update( i , Long.parseLong(st) , 
		   (ch!=null && ch.charAt(0)=='1') , (pg!=null && pg.charAt(0)=='1') );
}*/
- (void)update:(NSString*)i st:(NSInteger)st ch:(BOOL)ch pg:(BOOL)pg {
	self.yahooId=i;  
	self.status=st;
	self.onChat=ch;  
	self.onPager=pg;
	if (self.status != STATUS_CUSTOM) {
		self.customStatusMessage	= nil;
		self.customStatusBusy		= NO;
	}
}
// -----This is the old version, when 13=pager and 17=chat
-(void)update:(NSString*)i st:(NSString*)st ch:(NSString*)ch pig:(NSString*)pig {	
	[self update:i 
			  st:[st integerValue] 
			  ch:(ch!=nil && [ch characterAtIndex:0] =='1')
			  pg:(pig!=nil && [pig characterAtIndex:0]=='1')];
}
- (BOOL)isFriend {
	return (self.groupCount>0);
}
-(void)setCustom:(NSString*)m a:(NSString*)a {	
	self.customStatusMessage=m;  
	self.customStatusBusy= ([a characterAtIndex:0=='1']);
}
@end
